#include<iostream>
#include<cstdio>
using namespace std;
void MaxHeapFixDown(int a[], int i, int n)
{
    int j=2*i+1;
    int temp = a[i];
    while(j<n){
        if(j+1<n&&a[j]<a[j+1])
            ++j;
        if(temp>a[j])
            break;
        else{
            a[i]=a[j];
            i=j;
            j=2*i+1;
        }
    }
    a[i]=temp;
}
void HeapSort(int a[], int n){
    for(int i= n/2-1;i>=0;i--)
        MaxHeapFixDown(a,i,n);
    for(int i=n-1;i>=1;i--){
        swap(a[i],a[0]);
        MaxHeapFixDown(a,0,i);
    }
}
int main()
{
	int count;
	cin>>count;
	int read[count];
	for(int data=0;data<count;data++)
	{
		cin>>read[data];
	}
	HeapSort(read,count);
	for(int data=0;data<count;data++)
	{
		cout<<read[data]<<" ";
	}
	return 0;
}
